import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      utils:fileURLToPath(new URL ("./src/utils",import.meta.url)),
    },
  },
  server: {
    proxy : {
      /**
       * :5173/abcd         不能应该该规则
       * :5173/api          => :8001/api
       * :5173/api/hello    => :8001/api/hello
       */
      "/api": {
        // 目标服务
        target: "http://127.0.0.1:8001",
        /**
         * 路径重写
         * :5173/abcd         不能应该该规则
         * :5173/api          => :8001
         * :5173/api/hello    => :8001/hello
         */
        rewrite: (path) => path.replace("/api", ""),
      },
    }
  }
})
